package com.demo;

import java.util.ArrayList;
import java.util.HashMap;

import com.demo.AsyncBitmapLoader.ImageCallBack;
import com.demo.HomeListviewAdapter.ViewHolder;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 评论列表适配器
 * @author norsie
 * @create 12-12-20
 */
public class ColumnAdapter extends BaseAdapter
{
    private Context mContext;
    private ArrayList<HashMap<String,String>> mInfo;
    private LayoutInflater mInflater;
    
    public ColumnAdapter(Context context,ArrayList<HashMap<String,String>> info) {
        this.mContext=context;
        this.mInfo=info;
    }

    @Override
    public int getCount()
    {
        // TODO Auto-generated method stub
        return mInfo.size();
    }

    @Override
    public Object getItem(int position)
    {
        // TODO Auto-generated method stub
        return mInfo.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        // TODO Auto-generated method stub
        
        ViewHolder holder=null;
        if (convertView == null)
        {
            convertView = mInflater.inflate(R.layout.listview_item, null);
            holder = new ViewHolder();
            holder.tvName = (TextView) convertView.findViewById(R.id.reposts);
            holder.imgV = (ImageView) convertView.findViewById(R.id.comments);
            holder.tvText = (TextView) convertView.findViewById(R.id.text);
            holder.tvTime = (TextView) convertView.findViewById(R.id.forwarder);

            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder) convertView.getTag();
        }
        
        String tvName=mInfo.get(position).get("tvName").toString();
        String imgV=mInfo.get(position).get("imgV").toString();
        String tvText=mInfo.get(position).get("tvSex").toString();
        String tvTime=mInfo.get(position).get("tvLoc").toString();
        
        holder.tvName.setText(tvName);
        holder.tvText.setText(tvText);
        holder.tvTime.setText(tvTime);
        
        if(imgV.equals("true")) {
            holder.imgV.setVisibility(View.VISIBLE);
            holder.imgV.setBackgroundResource(R.drawable.ic_launcher);
        }
        else
            holder.imgV.setVisibility(View.INVISIBLE);
        
        return convertView;
    }
    
    private static class ViewHolder{
        TextView tvName;   //微博名
        ImageView imgV;   //V标识
        TextView tvText;   //评论内容
        TextView tvTime;   //评论时间
    }

}
